<template>
  <el-dialog
    :close-on-click-modal="false"
    :title="isEdit ? '修改' : '新增'"
    width="800px"
    :visible.sync="visible"
  >
    <el-form :model="form" ref="form" label-width="100px">
      <el-form-item label="类型">
        <el-select clearable v-model="form.ureportType" style="width: 100%">
          <el-option label="工作流" :value="1" />
          <el-option label="业务系统" :value="2" />
          <el-option label="其他" :value="9" />
        </el-select>
      </el-form-item>
      <el-form-item label="名称">
        <el-input v-model="form.ureportName" placeholder="请输入报表名称" />
      </el-form-item>
      <el-form-item label="下载文件名">
        <el-input v-model="form.downloadName" placeholder="请输入下载文件名" />
      </el-form-item>
      <!-- <el-form-item label="报表内容">
        <el-input v-model="form.ureportContent" placeholder="请输入报表内容" />
      </el-form-item>-->
    </el-form>
    <div slot="footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="handleUpdate">{{ isEdit? '修改' : '新增' }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { ureportUpdate, ureportCreate } from '@/api/system'
import { openNotification } from '@/utils/util'
export default {
  data() {
    return {
      isEdit: false,
      visible: false,
      form: {}
    }
  },
  methods: {
    edit(bool, obj) {
      this.isEdit = bool
      this.visible = true
      this.form = Object.assign({}, obj)
    },
    handleUpdate() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          let res = null,
            mes = null
          if (this.isEdit) {
            res = await ureportUpdate(this.form)
            mes = '修改操作成功'
          } else {
            res = await ureportCreate(this.form)
            mes = '新增操作成功'
          }
          if (res.state === '000000') {
            openNotification('success', mes)
            this.visible = false
            this.$emit('refresh')
          }
        }
      })
    }
  }
}
</script>
